package top.maof.book.service.myImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.maof.book.dao.LikesMapper;
import top.maof.book.model.Likes;
import top.maof.book.service.LikesService;

@Service
public class LikesServiceImpl extends ServiceImpl<LikesMapper, Likes> implements LikesService {
    @Override
    public boolean isExist(Integer userId, Integer bookId) {
        LambdaQueryWrapper<Likes> queryWrapper = Wrappers.<Likes>lambdaQuery();
        queryWrapper.eq(Likes::getUserId, userId).eq(Likes::getBookId, bookId);
        Likes one = this.getOne(queryWrapper);
        return one != null;
    }

    @Override
    public void remove(Integer userId, Integer bookId) {
        LambdaQueryWrapper<Likes> queryWrapper = Wrappers.<Likes>lambdaQuery();
        queryWrapper.eq(Likes::getUserId, userId).eq(Likes::getBookId, bookId);
        this.remove(queryWrapper);
    }

    @Override
    public int likesNum(Integer bookId) {
        int i = this.getBaseMapper().likesNum(bookId);
        return i;
    }
}
